package com.norma.netty.study.netty.disruptor;

import com.norma.netty.study.netty.disruptor.core.RingBufferWorkerPoolFactory;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.util.ReferenceCountUtil;

/**
 * @author zhangchaofeng
 * @date 2021/1/5
 * @description
 */
public class ClientHandler extends ChannelInboundHandlerAdapter {

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        try {
            TransData data = (TransData) msg;
            System.out.println(data.toString());
            RingBufferWorkerPoolFactory.getInstance()
                    .getMessageProducer("code:client:1").sendData(ctx, data);
        } finally {
            //如果最后一步不是写操作 那用完缓存需要释放
            ReferenceCountUtil.release(msg);
        }
    }
}
